package LinkList;

public class item141 {
    public boolean hasCycle(ListNode head) {
        if(head==null) return false;
        ListNode first = head;
        ListNode second = head;
        if(second.next==null||second.next==null)
        return false;
        else
            second = head.next.next;
        while (first!=null)
        {
            first = first.next;
            if(second.next.next==null)
                return false;
            else
                second = second.next.next;
            if(first==second)
                return true;
        }
        return false;
    }
}
